import { request } from "@/utils/request";
import type {
  DeleteParams,
  OrganizationParams,
  QueryByListParams,
  QueryParams,
  QueryResult,
} from "./typing";
import type { PageResult, ResponseBody } from "@/api/typing";

/**新增组织 */
export const add = (params: OrganizationParams) => {
  return request.post<OrganizationParams, ResponseBody>(
    "/organization/add",
    params
  );
};

/**修改组织 */
export const update = (params: OrganizationParams) => {
  return request.put<OrganizationParams, ResponseBody>(
    "/organization/update",
    params
  );
};

/**分页查询组织 */
export const queryByPage = (params: QueryParams) => {
  return request.get<QueryParams, ResponseBody<PageResult<QueryResult>>>(
    "/organization/page",
    { params }
  );
};

/**删除组织 */
export const del = (params: DeleteParams) => {
  return request.delete<DeleteParams, ResponseBody>("/organization/delete", {
    params,
  });
};

/**列表查询组织 */
export const queryByList = (params: QueryByListParams) => {
  return request.get<QueryByListParams, ResponseBody<QueryResult[]>>(
    "/organization/list",
    { params }
  );
};

/**列表查询当前用户默认角色组织 */
export const queryOrganizationList = () => {
  return request.get<null, ResponseBody<QueryResult[]>>(
    "/organization/role/list"
  );
};
